﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Http;

namespace Chess.Server
{
    public static class WebApiConfig
    {
        public static void Register(HttpConfiguration config)
        {
            //config.Routes.MapHttpRoute(
            //    name: "DefaultApi",
            //    routeTemplate: "api/{controller}/{id}",
            //    defaults: new { id = RouteParameter.Optional }
            //);

            config.Routes.MapHttpRoute(
                name: "GameApi",
                routeTemplate: "api/game/{gameId}/{action}/{sessionKey}",
                defaults: new { controller = "game", gameId = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "api/{controller}/{action}/{sessionKey}",
                defaults: new { sessionKey = RouteParameter.Optional }
            );

            config.Routes.MapHttpRoute(
                name: "FigureApi",
                routeTemplate: "api/figure/{gameId}/{action}/{sessionKey}",
                defaults: new { controller = "figure", sessionKey = RouteParameter.Optional}
            );

            var json = config.Formatters.JsonFormatter;
            json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
            config.Formatters.Remove(config.Formatters.XmlFormatter);
            //config.EnableSystemDiagnosticsTracing();
            //config.EnableCors(new EnableCorsAttribute("*", "*", "*"));
        }
    }
}
